<?php
class pay {
	private $model;
	private $members;		//会员信息
	private $MoenyCount; 	//商品总金额
	private $shops; 		//商品信息
	private $pay_type;		//支付类型
	private $fukuan_type;	//付款类型 买商品 充值
	private $dingdan_query = true;	//订单的	mysql_qurey 结果
	public $pay_type_bank = false;
	
	public $scookie = null;
	public $fufen = 0;
	public $fufen_to_money = 0;
	private $shoplist;
	private $scookies_arr;
	private $dingdancode;
	public $pay_type_str;
	public $uid;
	public $teamCreateInfo;
	private $zfield = "id,cateid,brandid,title,title2,keywords,money,oldmoney,yunjiage,zongrenshu,freight,thumb,time";
	
	public function __construct(){
		$this->model = new CoreModel();
	}
	
	public function setcart($json){
		$cart = json_decode(stripslashes($json),true);
		if (empty($cart)){
			return false;
		}else{
			$this->scookie = $cart;
			return true;
		}
	}
	public function init($uid=null,$pay_type=null,$execute_type=''){
		$this->model->startTrans();
		$this->members = query("SELECT * FROM `@#_member` where `uid` = '$uid' for update");
		$this->uid = $this->members['uid'];
		if($this->pay_type_bank){
			$pay_class = $this->pay_type_bank;
			$this->pay_type = query("SELECT * from `@#_pay` where `pay_class` = '$pay_class' and `pay_start` = '1'");
			$this->pay_type['pay_bank'] = $pay_type;
		}
		if(is_numeric($pay_type)){
			$this->pay_type =query("SELECT * from `@#_pay` where `pay_id` = '$pay_type' and `pay_start` = '1'");
			$this->pay_type['pay_bank'] = 'DEFAULT';
		}
		if(in_array($pay_type, array('jf','zh','all'))){
			$this->pay_type = $pay_type;
		}
		$this->fukuan_type=$execute_type;
		if ($execute_type == 'go_record'){
			return $this->go_record();
		}
		if ($execute_type == 'join_go_record'){
			return $this->join_go_record();
		}
		if ($execute_type == 'team_record'){
			return $this->team_record();
		}
		if ($execute_type == 'check_goods'){
			return $this->check_goods();
		}
		if ($execute_type == 'zf_record'){
			return $this->zf_record();
		}
		if ($execute_type == 'f_go_record'){
			return $this->f_go_record();
		}
	}

	private function f_go_record(){
		if(is_array($this->scookie)){
			$Cartlist = $this->scookie;
		}else{
			return '购物车内没有商品或已下架';
		}
		$shopids='';//商品ID
		if(is_array($Cartlist)){
			foreach($Cartlist as $key => $val){
				$shopids.=intval($key).',';
			}
			$shopids=str_replace(',0','',$shopids);
			$shopids=trim($shopids,',');
		}
		$shoplist=array();		//商品信息
		if($shopids!=NULL){
			$ids = explode(',', $shopids);
			$shoplist= query("SELECT * FROM `@#_shoplist` where `id` in($shopids) for update",3,$ids);
		}else{
			$this->model->rollback();
			return '购物车内没有商品或已下架';
		}
		if (empty($shoplist)){
			return '购物车内没有商品或已下架';
		}

		//删除库存为0的商品
		$_temp = array();
		$this->shoplist = array();
		$this->MoenyCount = 0;
		$_score = 0;
		$_persons = 0;
		foreach ($shoplist as $key => $value) {
			if ($value['zongrenshu'] <= 0){
				$_temp[] = $value['id'];
			}else{
				$value['cart_xiaoji'] = $Cartlist[$key]['num']*$value['yunjiage'];
				if ($value['freeMax'] < $Cartlist[$key]['num']){
					$Cartlist[$key]['num'] = $value['freeMax'];
				}
				$value['cart_gorenci'] = $Cartlist[$key]['num'];
				$_score += $value['cart_gorenci']*$value['yunjiage'];
				$_persons += $value['freeMin'];
				$this->MoenyCount += $value['cart_xiaoji']+$value['cart_freight'];
				$this->shoplist[$key] = $value;
			}
		}
		
		if ($_score > $this->members['score'] || $_persons > $this->members['invite_num']){
			return false;
		}

		if (!empty($this->shoplist)){
			$insert_html = '';
			$uid = $this->uid;
			$pay_type = '账户';
			$time=sprintf("%.3f",microtime(true));
			$ip = _get_ip_dizhi();
			$uphoto = get_user_name($uid,'img');
			$username = get_user_name($uid);
			$this->dingdancode = $dingdancode= pay_get_dingdan_code('A');//订单号
			if(count($this->shoplist) > 1){
				$dingdancode_tmp = 1;	//多个商品相同订单
			}else{
				$dingdancode_tmp = 0;	//单独商品订单
			}
			
			$scoreCount = 0;
			$personCount = 0;
			foreach($this->shoplist as $key=>$shop){
				$ret_data = array();
				//生成抢购码
				pay_get_shop_codes($shop['cart_gorenci'],$shop,$ret_data);
				$this->dingdan_query = $ret_data['query'];
				if(!$ret_data['query'])$this->dingdan_query = false;
				$codes = $ret_data['user_code']; //得到的购买码
				$codes_len= intval($ret_data['user_code_len']);		//得到购买码个数
				$money=$codes_len * $shop['yunjiage'];	//单条商品的总价格
				$this->MoenyCount += $money;	//总价格
				$scoreCount += $codes_len * $shop['yunjiage'];
				$personCount += $shop['freeMin'];
				$status='未付款,未发货,未完成';
				$shop['canyurenshu'] = intval($shop['canyurenshu']) + $codes_len;
				$shop['goods_count_num'] = $codes_len;
				$this->shoplist[$key] = $shop;
				if($codes_len){
					$insert_html.="('$dingdancode','$dingdancode_tmp','$uid','$username','$uphoto','$shop[id]','$shop[title]','$shop[qishu]','$codes_len','0','$codes','$pay_type','$ip','$status','$time'),";
				}
			}
			$sql="INSERT INTO `@#_member_go_record` (`code`,`code_tmp`,`uid`,`username`,`uphoto`,`shopid`,`shopname`,`shopqishu`,`gonumber`,`moneycount`,`goucode`,`pay_type`,`ip`,`status`,`time`) VALUES ";
			$sql.= trim($insert_html,',');
			if(empty($insert_html)){
				return false;
			}

			$query_1 = aud($sql); //生成订单成功
			
			//扣分，扣人数
			$remain_score = $this->members['score']-$scoreCount;
			$remain_person = $this->members['invite_num']-$personCount;
			$remain_query = aud("UPDATE `@#_member` SET `score`='$remain_score',`invite_num`='$remain_person' WHERE (`uid`='$uid')");
			$query_3 = $info = query("SELECT * FROM  `@#_member` WHERE (`uid`='$uid') LIMIT 1");
			$query_4 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '福分', '购买了商品', '{$scoreCount}', '$time')");
			$query_4_1 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '推荐人数', '购买了商品', '{$remain_person}', '$time')");
			$query_5 = true;
			$query_insert = true;
			$goods_count_num = 0;
			foreach($this->shoplist as $shop){
				if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
					aud("UPDATE `@#_shoplist` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
				}else{
					$sellnum = query("select sum(gonumber) as sellnum from `@#_member_go_record` where `shopid` = '$shop[id]'");
					$sellnum = $sellnum['sellnum'];
					$shenyurenshu = $shop['zongrenshu'] - $sellnum;
					$query = aud("UPDATE `@#_shoplist` SET `canyurenshu` = '$sellnum',`shenyurenshu` = '$shenyurenshu' WHERE `id`='$shop[id]'");
					if(!$query){
						$query_5=false;
					}
				}
				$goods_count_num += $shop['goods_count_num'];
			}			
			$dingdancode = $this->dingdancode;
			$query_6 = aud("UPDATE `@#_member_go_record` SET `status`='已付款,未发货,未完成' WHERE `code`='$dingdancode' and `uid` = '$uid'");
			$query_7 = $this->dingdan_query;
			$query_8 = aud("UPDATE `@#_caches` SET `value`=`value` + $goods_count_num WHERE `key`='goods_count_num'");
			$this->goods_count_num = $goods_count_num;
			if($query_1 && $query_3 && $query_4 && $query_4_1 && $query_5 && $query_6 && $query_7 && $query_insert && $query_8){
				if($info['score'] == $remain_score && $info['invite_num'] == $remain_person){
					$this->model->commit();
					foreach($this->shoplist as $shop){
						if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
							$this->model->startTrans();
							$query_insert = pay_insert_shop($shop,'add');
							if(!$query_insert){
								$this->model->rollback();
							}else{
								$this->model->commit();
							}
							aud("UPDATE `@#_shoplist` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
						}
					}
					return true;
				}else{
					$this->model->rollback();
					return false;
				}
			}else{
				$this->model->rollback();
				return false;
			}
			//处理完成
		}else{
			return '购物车没有商品';
		}
		
	}
	
	//0元购，直购
	private function zf_record(){
		if(is_array($this->scookie)){
			$Cartlist = $this->scookie;
		}else{
			return '购物车内没有商品或已下架';
		}
		$shopids='';//商品ID
		if(is_array($Cartlist)){
			foreach($Cartlist as $key => $val){
				$shopids.=intval($key).',';
			}
			$shopids=str_replace(',0','',$shopids);
			$shopids=trim($shopids,',');
		}
		$shoplist=array();		//商品信息
		if($shopids!=NULL){
			$ids = explode(',', $shopids);
			$shoplist= query("SELECT {$this->zfield} FROM `@#_jf_shoplist` where `id` in($shopids) for update",3,$ids);
		}else{
			$this->model->rollback();
			return '购物车内没有商品或已下架';
		}
		if (empty($shoplist)){
			return '购物车内没有商品或已下架';
		}

		//删除库存为0的商品
		$_temp = array();
		$this->shoplist = array();
		$this->MoenyCount = 0;
		foreach ($shoplist as $key => $value) {
			if ($value['zongrenshu'] <= 0){
				$_temp[] = $value['id'];
			}else{
				if ($value['money'] == 0){
					$value['cart_freight'] = $Cartlist[$key]['num']*$value['yunjiage'];
				}else{
					$value['cart_freight'] = $value['yunjiage'];
				}
				$value['cart_xiaoji'] = $Cartlist[$key]['num']*$value['money'];
				$value['cart_gorenci'] = $Cartlist[$key]['num'];
				$this->MoenyCount += $value['cart_xiaoji']+$value['cart_freight'];
				$this->shoplist[$key] = $value;
			}
		}
		return array('status' => 'ok','temp' => $_temp);
	}
	
	
	
	//检验是否有效
	private function check_goods(){
		if(is_array($this->scookie)){
			$Cartlist = $this->scookie;
		}else{
			return '购物车没有商品';
		}
		$shopids='';//商品ID
		if(is_array($Cartlist)){
			foreach($Cartlist as $key => $val){
				$shopids.=intval($key).',';
			}
			$shopids=str_replace(',0','',$shopids);
			$shopids=trim($shopids,',');
		}
		$shoplist=array();		//商品信息
		if($shopids!=NULL){
			$ids = explode(',', $shopids);
			$shoplist= query("SELECT * FROM `@#_teamgoods` where `id` in($shopids) and `q_uid` is null and `shenyurenshu` > 0 for update",3,$ids);
		}else{
			$this->model->rollback();
			return '购物车内没有商品';
		}
		if (empty($shoplist)){
			return '购物车内没有商品';
		}
		return 'ok';
	}
	
	//创团生成商品记录
	private function team_record(){
		if(is_array($this->scookie)){
			$Cartlist = $this->scookie;
		}else{
			return '购物车没有商品';
		}
		$model = $this->model;
		$this->members = M('member')->where(array('uid' => $this->uid))->find();
		if(empty($this->members)) return false;
		$shopids='';//商品ID
		if(is_array($Cartlist)){
			foreach($Cartlist as $key => $val){
				$shopids.=intval($key).',';
			}
			$shopids=str_replace(',0','',$shopids);
			$shopids=trim($shopids,',');
		}
		$shoplist=array();		//商品信息
		if($shopids!=NULL){
			$ids = explode(',', $shopids);
			$shoplist= query("SELECT * FROM `@#_teamgoods` where `id` in($shopids) and `q_uid` is null and `shenyurenshu` > 0 for update",3,$ids);
		}else{
			$this->model->rollback();
			return '购物车内没有商品';
		}
		if (!empty($shoplist)){
			$CartMoney = 0;
			foreach ($shoplist as $key => $value) {
				if ($Cartlist[$key]){
					$shoplist[$key]['cart_gorenci'] = $Cartlist[$key]['num'];
					$shoplist[$key]['cart_xiaoji'] = $Cartlist[$key]['money'];
					$shoplist[$key]['cart_shenyu'] = $value['shenyurenshu']-$Cartlist[$key]['num'];
					$CartMoney += $Cartlist[$key]['money'];
					$shoplist[$key]['q_group_name'] = $Cartlist[$key]['groupname'];
					$shoplist[$key]['q_create_uid'] = $this->uid;
				}
			}
			
			if ($this->members['money'] < $CartMoney){
				return '账户余额不足';
			}
			
			$_temp = array();
			foreach ($shoplist as $key => $value){
				$g_id = team_content_add_shop_install2($value);
				if (!$g_id) continue;
				$_temp[$key]['p_goods_id'] = $value['id'];
				$_temp[$key]['goods_id'] = $g_id;
				$_temp[$key]['cart_gorenci'] = $value['cart_gorenci'];
				$_temp[$key]['cart_xiaoji'] = $value['cart_xiaoji'];
				$_temp[$key]['cart_shenyu'] = $value['cart_shenyu'];
			}
			
			$this->shoplist = array();
			if (!empty($_temp)){
				foreach ($_temp as $key => $value) {
					$find = query("select * from `@#_teamgoods` where `id`='{$value['goods_id']}' limit 1");
					if (empty($find)){
						continue;
					}
					$find['cart_gorenci'] = $value['cart_gorenci'];
					$find['cart_xiaoji'] = $value['cart_xiaoji'];
					$find['cart_shenyu'] = $value['cart_shenyu'];
					$this->shoplist[$find['id']] = $find;
					if (!empty($Cartlist[$value['p_goods_id']])){
						$Cartlist[$value['p_goods_id']]['goods_id'] = $find['id'];
					}
				}
			}
			$insert_html = '';
			$uid = $this->uid;
			$pay_type = '账户';
			$time=sprintf("%.3f",microtime(true));
			$ip = _get_ip_dizhi();
			$uphoto = get_user_name($uid,'img');
			$username = get_user_name($uid);
			$this->dingdancode = $dingdancode= pay_get_dingdan_code('A');//订单号
			if(count($this->shoplist) > 1){
				$dingdancode_tmp = 1;	//多个商品相同订单
			}else{
				$dingdancode_tmp = 0;	//单独商品订单
			}
			foreach($this->shoplist as $key=>$shop){
				$ret_data = array();
				//生成抢购码
				pay_get_shop_codes($shop['cart_gorenci'],$shop,$ret_data);
					
				$this->dingdan_query = $ret_data['query'];
				if(!$ret_data['query'])$this->dingdan_query = false;
				$codes = $ret_data['user_code']; //得到的购买码
				$codes_len= intval($ret_data['user_code_len']);						//得到购买码个数
				$money=$codes_len * $shop['yunjiage'];								//单条商品的总价格
				$this->MoenyCount += $money;										//总价格
				$status='未付款,未发货,未完成';
				$shop['canyurenshu'] = intval($shop['canyurenshu']) + $codes_len;
				$shop['goods_count_num'] = $codes_len;
				$this->shoplist[$key] = $shop;
				if($codes_len){
					$insert_html.="('$dingdancode','$dingdancode_tmp','$uid','$username','$uphoto','$shop[id]','$shop[title]','$shop[qishu]','$codes_len','$money','$codes','$pay_type','$ip','$status','$time'),";
				}
			}
			$sql="INSERT INTO `@#_member_team_record` (`code`,`code_tmp`,`uid`,`username`,`uphoto`,`shopid`,`shopname`,`shopqishu`,`gonumber`,`moneycount`,`goucode`,`pay_type`,`ip`,`status`,`time`) VALUES ";
			$sql.= trim($insert_html,',');
			if(empty($insert_html)){
				return false;
			}
			
			if ($this->MoenyCount > $this->members['money']){
				return '账户余额不足';
			}
			$query_1 = aud($sql); //生成订单成功
			$fufen = include ROOT_PATH.'/core/config/user_fufen.ini.php';
			/*会员购买过账户剩余金额*/
			$Money = $this->members['money'] - $this->MoenyCount + $this->fufen_to_money;
			$query_fufen = true;
			$pay_zhifu_name = '账户';
			if($this->fufen_to_money){
				$myfufen = $this->members['score'] - $this->fufen;
				$query_fufen = aud("UPDATE `@#_member` SET `score`='$myfufen' WHERE (`uid`='$uid')");
				$pay_zhifu_name = '福分';
				$this->MoenyCount = $this->fufen;
			}
			
			//添加用户经验
			$jingyan = $this->members['jingyan'] + $fufen['z_shoppay'];
			$query_jingyan = aud("UPDATE `@#_member` SET `jingyan`='$jingyan' WHERE (`uid`='$uid')");	//经验值
			//更新用户账户金额
			$query_2 = aud("UPDATE `@#_member` SET `money`='$Money' WHERE (`uid`='$uid')");			//金额
			$query_3 = $info = query("SELECT * FROM  `@#_member` WHERE (`uid`='$uid') LIMIT 1");
			$query_4 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '$pay_zhifu_name', '购买了商品', '{$this->MoenyCount}', '$time')");
			$query_5 = true;
			$query_insert = true;
			$goods_count_num = 0;
			foreach($this->shoplist as $shop){
			if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
				aud("UPDATE `@#_teamgoods` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
			}else{
				$sellnum = query("select sum(gonumber) as sellnum from `@#_member_team_record` where `shopid` = '$shop[id]'");
				$sellnum = $sellnum['sellnum'];
				$shenyurenshu = $shop['zongrenshu'] - $sellnum;
				$query = aud("UPDATE `@#_teamgoods` SET `canyurenshu` = '$sellnum',`shenyurenshu` = '$shenyurenshu' WHERE `id`='$shop[id]'");
				if(!$query){
					$query_5=false;
				}
			}
				$goods_count_num += $shop['goods_count_num'];
			}
			
			//添加福分
			if(!$this->fufen_to_money){
				$mygoscore = $fufen['f_shoppay']*$goods_count_num;
				$mygoscore_text =  "购买了{$goods_count_num}人次商品";
				$myscore = $this->members['score'] + $mygoscore;
				$query_add_fufen_1 = aud("UPDATE `@#_member` SET `score`= '$myscore' WHERE (`uid`='$uid')");
				$query_add_fufen_2 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '1', '福分', '$mygoscore_text', '$mygoscore', '$time')");
				$query_fufen = ($query_add_fufen_1 && $query_add_fufen_2);
			}
			
			$dingdancode = $this->dingdancode;
			$query_6 = aud("UPDATE `@#_member_team_record` SET `status`='已付款,未发货,未完成' WHERE `code`='$dingdancode' and `uid` = '$uid'");
			$query_7 = $this->dingdan_query;
			$query_8 = aud("UPDATE `@#_caches` SET `value`=`value` + $goods_count_num WHERE `key`='goods_count_num'");
			$this->goods_count_num = $goods_count_num;
			
			if($query_fufen && $query_jingyan && $query_1 && $query_2 && $query_3 && $query_4 && $query_5 && $query_6 && $query_7 && $query_insert && $query_8){
				if($info['money'] == $Money){
					$model->commit();
					foreach($this->shoplist as $shop){
						if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
							$model->startTrans();
							$query_insert = team_pay_insert_shop($shop);
							if(!$query_insert){
								$model->rollback();
							}else{
								$model->commit();
							}
							aud("UPDATE `@#_teamgoods` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
						}
					}
					team_pay_go_yongjin($uid,$dingdancode);
					$this->teamCreateInfo = $this->shoplist;
					return true;
				}else{
					$model->rollback();
					return false;
				}
			}else{
				$model->rollback();
				return false;
			}
		}else{
			return '购物车内没有商品';
		}
	}
	
	//余额购买
	private function join_go_record(){
		if(is_array($this->scookie)){
			$Cartlist = $this->scookie;
		}else{
			return '购物车没有商品';
		}
	
		$shopids='';			//商品ID
		if(is_array($Cartlist)){
			foreach($Cartlist as $key => $val){
				$shopids.=intval($key).',';
			}
			$shopids=str_replace(',0','',$shopids);
			$shopids=trim($shopids,',');
	
		}
	
		$shoplist=array();		//商品信息
		if($shopids!=NULL){
			$ids = explode(',', $shopids);
			$shoplist= query("SELECT * FROM `@#_teamgoods` where `id` in($shopids) and `q_uid` is null and `shenyurenshu` > 0 for update",3,$ids);
		}else{
			$this->model->rollback();
			return '购物车内没有商品';
		}
	
		$MoenyCount= 0;
		$shopguoqi = 0;
		if(count($shoplist)>=1){
			$scookies_arr = array();
			$scookies_arr['MoenyCount'] = 0;
			foreach($Cartlist as $key => $val){
				$key=intval($key);
				if(isset($shoplist[$key]) && $shoplist[$key]['shenyurenshu'] != 0){
					if(($shoplist[$key]['xsjx_time'] != '0') && $shoplist[$key]['xsjx_time'] < time()){
						unset($shoplist[$key]);
						$shopguoqi = 1;
						continue;
					}
					$shoplist[$key]['cart_gorenci']=$val['num'] ? $val['num'] : 1;
					if($shoplist[$key]['cart_gorenci'] >= $shoplist[$key]['shenyurenshu']){
						$shoplist[$key]['cart_gorenci'] = $shoplist[$key]['shenyurenshu'];
					}
					$MoenyCount+=$shoplist[$key]['yunjiage']*$shoplist[$key]['cart_gorenci'];
					$shoplist[$key]['cart_xiaoji']=substr(sprintf("%.3f",$shoplist[$key]['yunjiage'] * $shoplist[$key]['cart_gorenci']),0,-1);
					$shoplist[$key]['cart_shenyu']=$shoplist[$key]['zongrenshu']-$shoplist[$key]['canyurenshu'];
					$scookies_arr[$key]['shenyu'] = $shoplist[$key]['cart_shenyu'];
					$scookies_arr[$key]['num'] = $shoplist[$key]['cart_gorenci'];
					$scookies_arr[$key]['money'] = intval($shoplist[$key]['yunjiage']);
					$scookies_arr['MoenyCount'] += intval($shoplist[$key]['cart_xiaoji']);
				}else{
					unset($shoplist[$key]);
				}
			}
			if(count($shoplist) < 1){
				$scookies_arr = '0';
				$this->model->rollback();
				if($shopguoqi){
					return '限时揭晓过期商品不能购买!';
				}else{
					return '购物车里没有商品!';
				}
			}
		}else{
			$scookies_arr = '0';
			$this->model->rollback();
			if ($this->pay_type_str == 'a'){
				return '购物车的商品已卖完或已下架,商品金额已退回您的'.getConfig('web_name').'账户';
			}elseif ($this->pay_type_str == 'b'){
				return '下手慢啦，被抢光啦!!';
			}
		}
	
		$this->MoenyCount=substr(sprintf("%.3f",$MoenyCount),0,-1);
		/**
		 *	最多能抵扣多少钱
		**/
		if($this->fufen){
			if($this->fufen >= $this->members['score']){
				$this->fufen = $this->members['score'];
			}
			//$fufen = include ROOT_PATH.'/core/config/user_fufen.ini.php';
			$fufen = include INC_PATH.'/member/lib/user_fufen.ini.php';
				
			if($fufen['fufen_yuan']){
				$this->fufen_to_money  = intval($this->fufen / $fufen['fufen_yuan']);
				if($this->fufen_to_money >= $this->MoenyCount){
					$this->fufen_to_money = $this->MoenyCount;
					$this->fufen = $this->fufen_to_money * $fufen['fufen_yuan'];
				}
			}else{
				$this->fufen_to_money = 0;
				$this->fufen = 0;
			}
		}else{
			$this->fufen_to_money = 0;
			$this->fufen = 0;
		}
		//总支付价格
		$this->MoenyCount = $this->MoenyCount - $this->fufen_to_money;
		$this->shoplist=$shoplist;
		$this->scookies_arr = $scookies_arr;
		return 'ok';
	}
	
	//余额购买 go_record
	private function go_record(){
		if(is_array($this->scookie)){
			$Cartlist = $this->scookie;
		}else{
			return '购物车没有商品';
		}
		
		$shopids='';			//商品ID
		if(is_array($Cartlist)){
			foreach($Cartlist as $key => $val){
				$shopids.=intval($key).',';
			}
			$shopids=str_replace(',0','',$shopids);
			$shopids=trim($shopids,',');
		
		}
		
		$shoplist=array();		//商品信息
		if($shopids!=NULL){
			$ids = explode(',', $shopids);
			$shoplist= query("SELECT * FROM `@#_shoplist` where `id` in($shopids) and `q_uid` is null and `shenyurenshu` > 0 for update",3,$ids);
		}else{
			$this->model->rollback();
			return '购物车内没有商品';
		}
		
		$MoenyCount= 0;
		$shopguoqi = 0;
		if(count($shoplist)>=1){
			$scookies_arr = array();
			$scookies_arr['MoenyCount'] = 0;
			foreach($Cartlist as $key => $val){
				$key=intval($key);
				if(isset($shoplist[$key]) && $shoplist[$key]['shenyurenshu'] != 0){
					if(($shoplist[$key]['xsjx_time'] != '0') && $shoplist[$key]['xsjx_time'] < time()){
						unset($shoplist[$key]);
						$shopguoqi = 1;
						continue;
					}
					$shoplist[$key]['cart_gorenci']=$val['num'] ? $val['num'] : 1;
					if($shoplist[$key]['cart_gorenci'] >= $shoplist[$key]['shenyurenshu']){
						$shoplist[$key]['cart_gorenci'] = $shoplist[$key]['shenyurenshu'];
					}
					$MoenyCount+=$shoplist[$key]['yunjiage']*$shoplist[$key]['cart_gorenci'];
					$shoplist[$key]['cart_xiaoji']=substr(sprintf("%.3f",$shoplist[$key]['yunjiage'] * $shoplist[$key]['cart_gorenci']),0,-1);
					$shoplist[$key]['cart_shenyu']=$shoplist[$key]['zongrenshu']-$shoplist[$key]['canyurenshu'];
					$scookies_arr[$key]['shenyu'] = $shoplist[$key]['cart_shenyu'];
					$scookies_arr[$key]['num'] = $shoplist[$key]['cart_gorenci'];
					$scookies_arr[$key]['money'] = intval($shoplist[$key]['yunjiage']);
					$scookies_arr['MoenyCount'] += intval($shoplist[$key]['cart_xiaoji']);
				}else{
					unset($shoplist[$key]);
				}
			}
			if(count($shoplist) < 1){
				$scookies_arr = '0';
				$this->model->rollback();
				if($shopguoqi){
					return '限时揭晓过期商品不能购买!';
				}else{
					return '购物车里没有商品!';
				}
			}
		}else{
			$scookies_arr = '0';
			$this->model->rollback();
			if ($this->pay_type_str == 'a'){
				return '购物车的商品已卖完或已下架,商品金额已退回您的'.getConfig('web_name').'账户';
			}elseif ($this->pay_type_str == 'b'){
				return '下手慢啦，被抢光啦!!';
			}
		}
		
		$this->MoenyCount=substr(sprintf("%.3f",$MoenyCount),0,-1);
		/**
		 *	最多能抵扣多少钱
		**/
		if($this->fufen){
			if($this->fufen >= $this->members['score']){
				$this->fufen = $this->members['score'];
			}
			//$fufen = include ROOT_PATH.'/core/config/user_fufen.ini.php';
			$fufen = include INC_PATH.'/member/lib/user_fufen.ini.php';
			
			if($fufen['fufen_yuan']){
				$this->fufen_to_money  = intval($this->fufen / $fufen['fufen_yuan']);
				if($this->fufen_to_money >= $this->MoenyCount){
					$this->fufen_to_money = $this->MoenyCount;
					$this->fufen = $this->fufen_to_money * $fufen['fufen_yuan'];
				}
			}else{
				$this->fufen_to_money = 0;
				$this->fufen = 0;
			}
		}else{
			$this->fufen_to_money = 0;
			$this->fufen = 0;
		}
		//总支付价格
		$this->MoenyCount = $this->MoenyCount - $this->fufen_to_money;
		$this->shoplist=$shoplist;
		$this->scookies_arr = $scookies_arr;
		return 'ok';
	}
	
	//付款
	public function join_go_pay($pay_checkbox){
		//如果账户余额大于商品金额
		if($this->members['money'] >= $this->MoenyCount){
			$uid=$this->members['uid'];
			//返回 true/false
			$pay_1 =  $this->join_pay_bag();
			if(!$pay_1){
				return $pay_1;
			}
			$dingdancode=$this->dingdancode;
			$pay_2 = pay_go_fund($this->goods_count_num);
			$pay_3 = team_pay_go_yongjin($uid,$dingdancode);
			return $pay_1;
		}
		//账户支付end
	
		//先充值再付款
		//这里走在线支付
		if(!is_array($this->pay_type)){
			return 'not_pay';
		}
		if(is_array($this->scookies_arr)){
			$scookie = serialize($this->scookies_arr);
		}else{
			$scookie= '0';
		}
	
		//使用账户余额支付
		if($pay_checkbox){
			//10-5 = 5
			$money = $this->MoenyCount - $this->members['money'];
			return $this->addmoney_record($money,$scookie,'gobuy');
		}else{
			//在线全额支付
			$this->MoenyCount;
			return $this->addmoney_record($this->MoenyCount,$scookie,'gobuy');
		}
		exit;
	}
	
	//0元购，直购
	public function zf_go_pay(){
		if($this->members['money'] >= $this->MoenyCount){
			//返回 true/false
			$uid=$this->members['uid'];
			$uphoto = $this->members['img'];
			$username = get_user_name($this->members);
			$insert_html='';
			$dingdancode= pay_get_dingdan_code('A');	//订单号
			$this->dingdancode = $dingdancode;
			if(count($this->shoplist)>1){
				$dingdancode_tmp = 1;	//多个商品相同订单
			}else{
				$dingdancode_tmp = 0;	//单独商品订单
			}
			$ip = _get_ip_dizhi();
			//订单时间
			$time=sprintf("%.3f",microtime(true));
			$this->MoenyCount=0;
			$user_dizhi = query("select * from `@#_member_dizhi` where `uid` = '$uid' and `default` = 'Y'");
			
			if ($user_dizhi){
				$address = $user_dizhi['sheng'].$user_dizhi['shi'].$user_dizhi['xian'].$user_dizhi['jiedao'].' 邮编：'.$user_dizhi['youbian'];
				$shouhuoren = $user_dizhi['shouhuoren'];
				$mobile = $user_dizhi['mobile'];
			}else{
				$address = '';
				$shouhuoren = get_user_name($uid,'username','all');
				$mobile = get_user_name($uid,'mobile','all');
			}
			
			foreach($this->shoplist as $key=>$shop){
				$money= $shop['cart_xiaoji']+$shop['cart_freight'];//单条商品的总价格
				$this->MoenyCount += $money; //总价格
				$status='未付款,未发货,未完成';
				$this->shoplist[$key] = $shop;
				$codes_len = $shop['cart_gorenci'];
				$pay_type = '账户';
				$freight = $shop['yunjiage'];
				
				if ($shop['money'] == 0){
					$not_money = 1;
				}elseif ($shop['money'] != 0){
					$not_money = 0;
				}
				
				$insert_html.="('$dingdancode','$dingdancode_tmp','$uid','$username','$uphoto','$shop[id]','$shop[title]','$shop[yunjiage]','$freight','$shop[cart_freight]','$address','$shouhuoren','$mobile','1','$codes_len','$money','$pay_type','$ip','$status','$time','$not_money'),";
			}
			$sql="INSERT INTO `@#_member_go_jf_record` (`code`,`code_tmp`,`uid`,`username`,`uphoto`,`shopid`,`shopname`,`yunjiage`,`freight`,`total_freight`,`address`,`shouhuoren`,`mobile`,`shopqishu`,`gonumber`,`moneycount`,`pay_type`,`ip`,`status`,`time`,`not_money`) VALUES ";
			$sql.= trim($insert_html,',');
			if(empty($insert_html)){
				return false;
			}
			if(aud($sql)){
				$pay_1 =  $this->zf_pay_bag();
				if(!$pay_1){
					return $pay_1;
				}
				return $pay_1;
			}
			return false;
		}else{
			return false;
		}
	}
	
	private function zf_pay_bag(){
		$this->model->startTrans();
		$time=time();
		$uid=$this->members['uid'];
		$Money = $this->members['money'] - $this->MoenyCount;
		//更新用户账户金额
		$query_2 = aud("UPDATE `@#_member` SET `money`='$Money' WHERE (`uid`='$uid')");			//金额
		$query_3 = $info = query("SELECT * FROM  `@#_member` WHERE (`uid`='$uid') LIMIT 1");
		$query_4 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '账户', '购买了商品', '{$this->MoenyCount}', '$time')");
		$dingdancode=$this->dingdancode;
		$query_6 = aud("UPDATE `@#_member_go_jf_record` SET `status`='已付款,未发货,未完成' WHERE `code`='$dingdancode' and `uid` = '$uid'");
		if($query_2 && $query_3 && $query_4 && $query_6){
			if($info['money'] == $Money){
				$this->model->commit();
				foreach($this->shoplist as $shop){
					//aud("UPDATE `@#_jf_shoplist` SET `zongrenshu`=zongrenshu-$shop[cart_gorenci] where `id` = '$shop[id]'");
					aud("UPDATE `@#_jf_shoplist` SET `canyurenshu`=canyurenshu+$shop[cart_gorenci],`shenyurenshu`=shenyurenshu-$shop[cart_gorenci] where `id` = '$shop[id]'");
				}
				return true;
			}else{
				$this->model->rollback();
				return false;
			}
		}else{
			$this->model->rollback();
			return false;
		}
	}
	
	//付款
	public function go_pay($pay_checkbox){
		//如果账户余额大于商品金额
		if($this->members['money'] >= $this->MoenyCount){
			$uid=$this->members['uid'];
			//返回 true/false
			$pay_1 =  $this->pay_bag();
			if(!$pay_1){
				return $pay_1;
			}
			$dingdancode=$this->dingdancode;
			$pay_2 = pay_go_fund($this->goods_count_num);
			$pay_3 = pay_go_yongjin($uid,$dingdancode);
			return $pay_1;
		}
		//账户支付end
		
		//先充值再付款
		//这里走在线支付
		if(!is_array($this->pay_type)){
			return 'not_pay';
		}
		if(is_array($this->scookies_arr)){
			$scookie = serialize($this->scookies_arr);
		}else{
			$scookie= '0';
		}
	
		//使用账户余额支付
		if($pay_checkbox){
			//10-5 = 5
			$money = $this->MoenyCount - $this->members['money'];
			return $this->addmoney_record($money,$scookie,'gobuy');
		}else{
			//在线全额支付
			$this->MoenyCount;
			return $this->addmoney_record($this->MoenyCount,$scookie,'gobuy');
		}
		exit;
	}
	
	//生成订单
	private function go_set_dingdan($pay_type='',$dingdanzhui=''){
		$uid=$this->members['uid'];
		$uphoto = $this->members['img'];
		$username = get_user_name($this->members);
		$insert_html='';
		$this->dingdancode = $dingdancode= pay_get_dingdan_code($dingdanzhui);		//订单号
		if(count($this->shoplist)>1){
			$dingdancode_tmp = 1;	//多个商品相同订单
		}else{
			$dingdancode_tmp = 0;	//单独商品订单
		}
	
		$ip = _get_ip_dizhi();
	
		//订单时间
		$time=sprintf("%.3f",microtime(true));
		$this->MoenyCount=0;
	
		foreach($this->shoplist as $key=>$shop){
	
			$ret_data = array();
			//生成抢购码，写入订单信息
			pay_get_shop_codes($shop['cart_gorenci'],$shop,$ret_data);
			$this->dingdan_query = $ret_data['query'];
			if(!$ret_data['query'])$this->dingdan_query = false;
			$codes = $ret_data['user_code']; //得到的购买码
			$codes_len= intval($ret_data['user_code_len']);						//得到购买码个数
			$money=$codes_len * $shop['yunjiage'];								//单条商品的总价格
			$this->MoenyCount += $money;										//总价格
			$status='未付款,未发货,未完成';
			$shop['canyurenshu'] = intval($shop['canyurenshu']) + $codes_len;
			$shop['goods_count_num'] = $codes_len;
			$this->shoplist[$key] = $shop;
			if($codes_len){
				$insert_html.="('$dingdancode','$dingdancode_tmp','$uid','$username','$uphoto','$shop[id]','$shop[title]','$shop[qishu]','$codes_len','$money','$codes','$pay_type','$ip','$status','$time'),";
			}
		}
		$sql="INSERT INTO `@#_member_team_record` (`code`,`code_tmp`,`uid`,`username`,`uphoto`,`shopid`,`shopname`,`shopqishu`,`gonumber`,`moneycount`,`goucode`,`pay_type`,`ip`,`status`,`time`) VALUES ";
		$sql.= trim($insert_html,',');
		if(empty($insert_html)){
			return false;
		}
		return aud($sql);
	}
	
	//账户里支付
	private function join_pay_bag(){
		$time=time();
		$uid=$this->members['uid'];
// 		$fufen = include ROOT_PATH.'/core/config/user_fufen.ini.php';
		$fufen = include INC_PATH.'/member/lib/user_fufen.ini.php';
		$query_1 = $this->go_set_dingdan('账户','A');
	
		/*会员购买过账户剩余金额*/
		$Money = $this->members['money'] - $this->MoenyCount + $this->fufen_to_money;
		$query_fufen = true;
		$pay_zhifu_name = '账户';
		if($this->fufen_to_money){
			$myfufen = $this->members['score'] - $this->fufen;
			$query_fufen = aud("UPDATE `@#_member` SET `score`='$myfufen' WHERE (`uid`='$uid')");
			$pay_zhifu_name = '福分';
			$this->MoenyCount = $this->fufen;
		}
	
		//添加用户经验
		$jingyan = $this->members['jingyan'] + $fufen['z_shoppay'];
		$query_jingyan = aud("UPDATE `@#_member` SET `jingyan`='$jingyan' WHERE (`uid`='$uid')");	//经验值
	
		//更新用户账户金额
		$query_2 = aud("UPDATE `@#_member` SET `money`='$Money' WHERE (`uid`='$uid')");			//金额
		$query_3 = $info = query("SELECT * FROM  `@#_member` WHERE (`uid`='$uid') LIMIT 1");
		$query_4 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '$pay_zhifu_name', '购买了商品', '{$this->MoenyCount}', '$time')");
		$query_5 = true;
		$query_insert = true;
	
		$goods_count_num = 0;
		foreach($this->shoplist as $shop){
			if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
				aud("UPDATE `@#_teamgoods` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
			}else{
				$sellnum = query("select sum(gonumber) as sellnum from `@#_member_team_record` where `shopid` = '$shop[id]'");
				$sellnum = $sellnum['sellnum'];
				$shenyurenshu = $shop['zongrenshu'] - $sellnum;
				$query = aud("UPDATE `@#_teamgoods` SET `canyurenshu` = '$sellnum',`shenyurenshu` = '$shenyurenshu' WHERE `id`='$shop[id]'");
				if(!$query){
					$query_5=false;
				}
			}
			$goods_count_num += $shop['goods_count_num'];
		}
	
		//添加福分
		if(!$this->fufen_to_money){
			$mygoscore = $fufen['f_shoppay']*$goods_count_num;
			$mygoscore_text =  "购买了{$goods_count_num}人次商品";
			$myscore = $this->members['score'] + $mygoscore;
			$query_add_fufen_1 = aud("UPDATE `@#_member` SET `score`= '$myscore' WHERE (`uid`='$uid')");
			$query_add_fufen_2 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '1', '福分', '$mygoscore_text', '$mygoscore', '$time')");
			$query_fufen = ($query_add_fufen_1 && $query_add_fufen_2);
		}
	
		$dingdancode=$this->dingdancode;
		$query_6 = aud("UPDATE `@#_member_team_record` SET `status`='已付款,未发货,未完成' WHERE `code`='$dingdancode' and `uid` = '$uid'");
		$query_7 = $this->dingdan_query;
		$query_8 = aud("UPDATE `@#_caches` SET `value`=`value` + $goods_count_num WHERE `key`='goods_count_num'");
		$this->goods_count_num = $goods_count_num;
	
		if($query_fufen && $query_jingyan && $query_1 && $query_2 && $query_3 && $query_4 && $query_5 && $query_6 && $query_7 && $query_insert && $query_8){
			if($info['money'] == $Money){
				$this->model->commit();
				foreach($this->shoplist as $shop){
					if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
						$this->model->startTrans();
						$query_insert = team_pay_no_insert_shop($shop);
						if(!$query_insert){
							$this->model->rollback();
						}else{
							$this->model->commit();
						}
						aud("UPDATE `@#_teamgoods` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
					}
				}
				return true;
			}else{
				$this->model->rollback();
				return false;
			}
		}else{
			$this->model->rollback();
			return false;
		}
	
	}
	
	//账户里支付
	private function pay_bag(){
		$time=time();
		$uid=$this->members['uid'];
// 		$fufen = include ROOT_PATH.'/core/config/user_fufen.ini.php';
		$fufen = include INC_PATH.'/member/lib/user_fufen.ini.php';
		$query_1 = $this->set_dingdan('账户','A');
		/*会员购买过账户剩余金额*/
		$Money = $this->members['money'] - $this->MoenyCount + $this->fufen_to_money;
		$query_fufen = true;
		$pay_zhifu_name = '账户';
		if($this->fufen_to_money){
			$myfufen = $this->members['score'] - $this->fufen;
			$query_fufen = aud("UPDATE `@#_member` SET `score`='$myfufen' WHERE (`uid`='$uid')");
			$pay_zhifu_name = '福分';
			$this->MoenyCount = $this->fufen;
		}
		//添加用户经验
		$jingyan = $this->members['jingyan'] + $fufen['z_shoppay'];
		$query_jingyan = aud("UPDATE `@#_member` SET `jingyan`='$jingyan' WHERE (`uid`='$uid')");	//经验值
	
		//更新用户账户金额
		$temp_info = query("SELECT * FROM  `@#_member` WHERE (`uid`='$uid') LIMIT 1");
		$query_2 = aud("UPDATE `@#_member` SET `money`='$Money' WHERE (`uid`='$uid')");			//金额
		if ($this->fufen_to_money && !$query_2){
			if ($temp_info['money'] == $Money){
				$query_2 = true;
			}
		}
		
		if ($query_2){
			file_put_contents('pay.txt', 123);
		}
		$info = query("SELECT * FROM  `@#_member` WHERE (`uid`='$uid') LIMIT 1");
		$query_3 = $info;
		$query_4 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '-1', '$pay_zhifu_name', '购买了商品', '{$this->MoenyCount}', '$time')");
		$query_5 = true;
		$query_insert = true;
		$goods_count_num = 0;
		foreach($this->shoplist as $shop){
			if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
				aud("UPDATE `@#_shoplist` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
			}else{
				$sellnum = query("select sum(gonumber) as sellnum from `@#_member_go_record` where `shopid` = '$shop[id]'");
				$sellnum = $sellnum['sellnum'];
				$shenyurenshu = $shop['zongrenshu'] - $sellnum;
				$query = aud("UPDATE `@#_shoplist` SET `canyurenshu` = '$sellnum',`shenyurenshu` = '$shenyurenshu' WHERE `id`='$shop[id]'");
				if(!$query){
					$query_5=false;
				}
			}
			$goods_count_num += $shop['goods_count_num'];
		}
	
		//添加福分
		if(!$this->fufen_to_money){
			$mygoscore = $fufen['f_shoppay']*$goods_count_num;
			$mygoscore_text =  "购买了{$goods_count_num}人次商品";
			$myscore = $this->members['score'] + $mygoscore;
			$query_add_fufen_1 = aud("UPDATE `@#_member` SET `score`= '$myscore' WHERE (`uid`='$uid')");
			$query_add_fufen_2 = aud("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '1', '福分', '$mygoscore_text', '$mygoscore', '$time')");
			$query_fufen = ($query_add_fufen_1 && $query_add_fufen_2);
		}
	
		$dingdancode=$this->dingdancode;
		$query_6 = aud("UPDATE `@#_member_go_record` SET `status`='已付款,未发货,未完成' WHERE `code`='$dingdancode' and `uid` = '$uid'");
		$query_7 = $this->dingdan_query;
		$query_8 = aud("UPDATE `@#_caches` SET `value`=`value` + $goods_count_num WHERE `key`='goods_count_num'");
		$this->goods_count_num = $goods_count_num;
	
		if($query_fufen && $query_jingyan && $query_1 && $query_2 && $query_3 && $query_4 && $query_5 && $query_6 && $query_7 && $query_insert && $query_8){
			if($info['money'] == $Money){
				$this->model->commit();
				foreach($this->shoplist as $shop){
				if($shop['canyurenshu'] >= $shop['zongrenshu'] && $shop['maxqishu'] >= $shop['qishu']){
					$this->model->startTrans();
					$query_insert = pay_insert_shop($shop,'add');
					if(!$query_insert){
						$this->model->rollback();
					}else{
						$this->model->commit();
					}
					aud("UPDATE `@#_shoplist` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0' where `id` = '$shop[id]'");
				}
			}
				return true;
			}else{
				$this->model->rollback();
				return false;
			}
		}else{
			$this->model->rollback();
			return false;
		}
	
	}
	
	//生成订单
	private function set_dingdan($pay_type='',$dingdanzhui=''){
		$uid=$this->members['uid'];
		$uphoto = $this->members['img'];
		$username = get_user_name($this->members);
		$insert_html='';
		$this->dingdancode = $dingdancode= pay_get_dingdan_code($dingdanzhui);		//订单号
	
		if(count($this->shoplist)>1){
			$dingdancode_tmp = 1;	//多个商品相同订单
		}else{
			$dingdancode_tmp = 0;	//单独商品订单
		}
	
		$ip = _get_ip_dizhi();
	
		//订单时间
		$time=sprintf("%.3f",microtime(true));
		$this->MoenyCount=0;
		foreach($this->shoplist as $key=>$shop){
	
			$ret_data = array();
			//生成抢购码，写入订单信息
			pay_get_shop_codes($shop['cart_gorenci'],$shop,$ret_data);
	
			$this->dingdan_query = $ret_data['query'];
			if(!$ret_data['query'])$this->dingdan_query = false;
			$codes = $ret_data['user_code']; //得到的购买码
			$codes_len= intval($ret_data['user_code_len']);//得到购买码个数
			$money=$codes_len * $shop['yunjiage'];//单条商品的总价格
			$this->MoenyCount += $money; //总价格
			$status='未付款,未发货,未完成';
			$shop['canyurenshu'] = intval($shop['canyurenshu']) + $codes_len;
			$shop['goods_count_num'] = $codes_len;
			$this->shoplist[$key] = $shop;
			if($codes_len){
				$insert_html.="('$dingdancode','$dingdancode_tmp','$uid','$username','$uphoto','$shop[id]','$shop[title]','$shop[qishu]','$codes_len','$money','$codes','$pay_type','$ip','$status','$time'),";
			}
		}
		$sql="INSERT INTO `@#_member_go_record` (`code`,`code_tmp`,`uid`,`username`,`uphoto`,`shopid`,`shopname`,`shopqishu`,`gonumber`,`moneycount`,`goucode`,`pay_type`,`ip`,`status`,`time`) VALUES ";
		$sql.= trim($insert_html,',');
		if(empty($insert_html)){
			return false;
		}
		return aud($sql);
	}
	
}